package com.park.web.controller;


import com.park.web.base.baseOperation.BaseController;
import com.park.web.core.wrapper.WrapMapper;
import com.park.web.core.wrapper.Wrapper;
import com.park.web.model.domain.basSystemDataDict;
import com.park.web.model.dto.basSystemDataDictDto;
import com.park.web.model.vo.basSystemDataDictVo;
import com.park.web.service.basSystemDataDictService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;
import java.util.UUID;

@RestController
@Api(value = "WEB - BasSystemDataDictController", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@RequestMapping(value = "basSystemDataDict", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class BasSystemDataDictController extends BaseController {

    @Autowired
    basSystemDataDictService ibasSystemDataDictService;

    @PostMapping("/selectAll")
    @ApiOperation(value = "查询树形结构数据字典", notes = "查询树形结构数据字典")
    public Wrapper<List<basSystemDataDictVo>> selectAllList() {
        var list = ibasSystemDataDictService.selectAllList();
        return WrapMapper.okWithoutMessage(list);
    }

    @GetMapping("/queryWithPage")
    @ApiOperation(value = "查询所有信息", notes = "查询所有信息")
    public Wrapper queryWithPage(basSystemDataDictDto entity) {
        var list = ibasSystemDataDictService.queryWithPage(entity);
        return WrapMapper.okWithoutMessage(list);
    }

    @PostMapping("/save")
    @ApiOperation(value = "新增数据字典", notes = "新增数据字典")
    public Wrapper Save(basSystemDataDict entity) {
        entity.setId(UUID.randomUUID().toString().replace("-", ""));
        entity.setCreateTime(new Date());
        entity.setBottLevel(1);
        ibasSystemDataDictService.save(entity);
        return WrapMapper.ok();
    }

    @PostMapping("/update")
    @ApiOperation(value = "修改数据字典", notes = "修改数据字典")
    public Wrapper Update(basSystemDataDict entity) {
        ibasSystemDataDictService.update(entity);
        return WrapMapper.ok();
    }

    @GetMapping("/queryById/{dataDictId}")
    @ApiOperation(value = "修改数据字典", notes = "修改数据字典")
    public Wrapper QueryById(@PathVariable("dataDictId") String dataDictId) {
        var entity = ibasSystemDataDictService.selectByKey(dataDictId);
        return WrapMapper.okWithoutMessage(entity);
    }

    @PostMapping("/delDataDictById")
    @ApiOperation(value = "删除数据字典", notes = "删除数据字典")
    public Wrapper delDataDictById(basSystemDataDict entity) {
        var result = ibasSystemDataDictService.deleteByIds(entity.getId());
        return WrapMapper.ok(result);
    }

    @GetMapping("/findDataDictListByParentKey/{parentModelKey}")
    @ApiOperation(value = "根据父节点查找子节点", notes = "根据父节点查找子节点")
    public Wrapper findDataDictListByParentKey(@PathVariable("parentModelKey") String parentModelKey) {
        var list = ibasSystemDataDictService.findDataDictListByParentKey(parentModelKey);
        return WrapMapper.okWithoutMessage(list);
    }
}
